#!/bin/bash
#2020年5月3日20:24:05
#auto install mysql database
#by author www.jfedu.net
###########################
#Install mysql by source code
yum install -y wget gcc c ncurses-devel libaio bison gcc-c++ 
yum install -y git cmake ncurses-devel ncurses
wget -c http://mirrors.163.com/mysql/Downloads/MySQL-5.5/mysql-5.5.60.tar.gz
tar -zxvf mysql-5.5.60.tar.gz
cd mysql-5.5.60/
pwd
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITH_XTRADB_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EXTRA_CHARSETS=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_BIG_TABLES=1 \
-DWITH_DEBUG=0
make
make install
cp support-files/my-large.cnf /usr/local/mysql/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
mkdir -p /data/mysql
useradd -s /sbin/nologin mysql
chown -R mysql. /data/mysql
/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql/

chkconfig --level 35 mysqld on
service mysqld start
chkconfig --add mysqld
